package com.example.zyfypt516wh.fragment;

import android.content.Context;
import android.content.SharedPreferences;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

public abstract class BaseFragment extends Fragment {

    private SharedPreferences sp;
    protected Context context;

    @Override
    public void onAttach(@NonNull Context context) {
        this.context = context;
//        sp = context.getSharedPreferences("login", Context.MODE_PRIVATE);//需与保存时的文件名一致
        sp = context.getSharedPreferences("user", Context.MODE_PRIVATE);//需与保存时的文件名一致
        super.onAttach(context);
    }

    protected String getSessionID() { //记住密码功能所保存的 sessionID
        return sp.getString("sessionID", "");//需与保存时的关键字一致
    }

    protected String getUsername() { //记住密码功能所保存的用户名
        return sp.getString("username", "");//需与保存时的关键字一致
    }
}
